/**
 * Copyright (C), 2019-2020, 宇信融汇
 * FileName: ComparableTest
 * Author:   xbliu
 * Date:     2020/7/13 8:48
 * Description: Comparable接口实现
 * History:
 * <author>          <time>          <version>          <desc>
 * xbliu           修改时间           版本号              描述
 */
package c_009.comparable;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Classname ComparableTest
 * @Description TODO
 * @Date 2020/7/13 8:48
 * @Created by xbliu
 */
public class ComparableTest {
    @Test
    public void test1() {
        String[] arr = new String[]{"AA", "ZZ", "KK", "DD", "CC", "BB"};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    @Test
    public void test2() {
        String[] arr = new String[]{"AA", "ZZ", "KK", "DD", "CC", "BB"};
        Arrays.sort(arr, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof String && o2 instanceof String) {
                    String s1 = (String) o1;
                    String s2 = (String) o2;
                    System.out.println(s1.compareTo(s2));
                    return -s1.compareTo(s2);
                }
                throw new RuntimeException("");
            }
        });

        System.out.println(Arrays.toString(arr));
    }
}
